<?php

class reservednumbers_record
{
	var $driver;
	var $number;

	function reservednumbers_record($record='')
	{
		global $db, $lang;
		
		$this->driver = '<a href="drivers.php?id=' . $record['r_driver'] . '">' . $record['user_drivername'] . '</a>';
		$this->number = $record['r_no'];
        
	}
		
	function render()
	{		
		global $skin_dir;
				
		$driver = $this->driver;
		$number = $this->number;
			 
    	include $skin_dir . 'tpl/reservednumber.tpl';
	}
}

class reservednumbers
{
	var $mess;
	var $champid;
        
	var $toRender = Array();

	function reservednumbers($champid)
	{
		$this->champid = $champid;
		global $db, $lang;
		include_once('includes/addMessage.php');
		include_once('includes/renderInclude.php');
		
		        
        //get the record
		
		$q = "SELECT *, pf_drivername as user_drivername  
			  FROM " . RESERVEDNUMBERS_TABLE . ", " . USERS_TABLE . " u, " . DRIVERNAME_TABLE . " d
			  WHERE u.user_id = d.user_id AND u.user_id = r_driver AND r_champ = " . 
                   $this->champid . " ORDER BY r_no ASC";
		$result = $db->sql_query($q);
                
		$this->toRender[] = new renderInclude('tpl/tableStart.tpl');
		
		while($row = $db->sql_fetchrow($result)) 
		{
			$this->toRender[] = new reservednumbers_record($row);
		}
		
		$this->toRender[] = new renderInclude('tpl/tableEnd.tpl');
	}

	function render()
	{		
		foreach( $this->toRender as $key => $value){
			$value->render();
		}
		
	}
}


class reserveddivisions_record
{
	var $driver;
	var $number;

	function reserveddivisions_record($record='')
	{
		global $db, $lang;
		
		$this->driver = '<a href="drivers.php?id=' . $record['r_driver'] . '">' . $record['user_drivername'] . '</a>';
		$this->division = $record['d_title'];
        
	}
		
	function render()
	{		
		global $skin_dir;
				
		$driver = $this->driver;
		$division = $this->division;
			 
    	include $skin_dir . 'tpl/reserveddivision.tpl';
	}
}

class reserveddivisions
{
	var $mess;
	var $champid;
        
	var $toRender = Array();

	function reserveddivisions($champid)
	{
		$this->champid = $champid;
		global $db, $lang;
		include_once('includes/addMessage.php');
		include_once('includes/renderInclude.php');
		
		        
        //get the record
		
		$q = "SELECT *, pf_drivername as user_drivername " .
				" FROM " . RESERVEDDIVISIONS_TABLE . ", " . USERS_TABLE . " u, "  . DRIVERNAME_TABLE . " d, " . DIVISIONS_TABLE . 
				" WHERE d_id = r_division AND u.user_id = r_driver AND u.user_id = d.user_id AND r_champ = " . $this->champid . 
				" ORDER BY d_order, user_drivername ASC";

		$result = $db->sql_query($q);
                
		$this->toRender[] = new renderInclude('tpl/tableStart.tpl');
		
		while($row = $db->sql_fetchrow($result)) 
		{
			$this->toRender[] = new reserveddivisions_record($row);
		}
		
		$this->toRender[] = new renderInclude('tpl/tableEnd.tpl');
	}

	function render()
	{		
		foreach( $this->toRender as $key => $value){
			$value->render();
		}
		
	}
}
?>